package org.wkg.lesson03;

import java.util.concurrent.TimeUnit;

public class Demo_302 {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("my thread....");
            }
        }, "练习1");
        System.out.println(thread.getName() + " 线程存活：" + thread.isAlive());
        System.out.println(thread.getName() + " 线程状态为：" + thread.getState());
        System.out.println("---------------------------");
        thread.start();
        System.out.println(thread.getName() + " 线程存活：" + thread.isAlive());
        System.out.println(thread.getName() + " 线程状态为：" + thread.getState());
        System.out.println("---------------------------");
        TimeUnit.MILLISECONDS.sleep(500);
        System.out.println(thread.getName() + " 线程存活：" + thread.isAlive());
        System.out.println(thread.getName() + " 线程状态为：" + thread.getState());
        System.out.println("---------------------------");
        thread.join();
        System.out.println(thread.getName() + " 线程存活：" + thread.isAlive());
        System.out.println(thread.getName() + " 线程状态为：" + thread.getState());
    }
}
